
// Copyright (C) 2007 Richard Uhler
// This file is part of Esiply.
//
// Esiply is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, Version 2,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include <assert.h>

#include "ArgumentListExpression.h"
#include "List.h"
#include "Value.h"

ArgumentListExpression::ArgumentListExpression()
{}

ArgumentListExpression::ArgumentListExpression(Expression* arg)
{
    m_args.push_back(arg);
}

Value* ArgumentListExpression::evaluate(Scope* scope)
{
    // Ecma 11.2.4 (my interpretation)
    // 1. Evaluate each expression
    // 2. Call get value on the result
    // 3. Add those results to a list, and return the list
    List* list = new List();
    for (unsigned int i = 0; i < m_args.size(); i++)
    {
        Value* arg = m_args[i]->evaluate(scope)->getValue();
        CHECK_EXCEPTION(arg);
        list->push_back(arg);
    }
    return list;
}

void ArgumentListExpression::push_back(Expression* arg)
{
    m_args.push_back(arg);
}

